#include "Floor.h"


Floor::Floor(void)
{
}


Floor::~Floor(void)
{
}


void Floor::init(void)
{
	//Empty the queue
	while(!floorQ.empty())
		floorQ.pop();

	//init the CallButton
	floorCallButton.init();
}


void Floor::loadQ(Ticket * ticket)
{
	//Store ticket in the queue
	floorQ.push(ticket);

	//Call Callbutton
	floorCallButton.callElevator();
		
}


bool Floor::isCallPressed(int elevID)
{
	//Call CallButton isButtonPushed
	return floorCallButton.isButtonPushed( (elevID) );
	//if( floorCallButton.isButtonPushed(elevID) )
	//{
	//	floorCallButton.callElevator();
	//	return true;
	//}
	//return false;
}

//BUG Walker: we need to pass a pointer to a pointer here for this to work
bool Floor::getTicket(Ticket ** ticket, int elevID)
{
	//Call CallButton elevator loading
	floorCallButton.elevatorLoading(elevID);

	//if floorQ is empty return false
	if(floorQ.empty())
	{
		return false;
	}
	else
	{
		//return ticket
		//ticket = floorQ.front();//CHANGE THIS!!!!
		*ticket = floorQ.front();
		//remove front ticket
		floorQ.pop();
		//confirm there is a ticket in the queue
		return true;
	}
	
}


void Floor::elevatorLeaving(int elevID)
{
	//return true if floorQ is not empty, return false if floorQ is empty
	floorCallButton.elevatorLeaving( elevID, floorQ.empty() );
}